﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

namespace Journeo_backend.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [AllowAnonymous]
    public class PlanAttractionController : ControllerBase
    {
        private readonly IPlanAttractionService _planAttractionService;

        public PlanAttractionController(IPlanAttractionService planAttractionService)
        {
            _planAttractionService = planAttractionService;
        }


        [HttpPost("create")]
        [SwaggerOperation(Summary = "创建一个新的计划景点", Description = "创建一个新的计划景点")]
        [SwaggerResponse(200, "创建成功", typeof(Response<PlanAttraction>))]
        [SwaggerResponse(400, "创建失败")]
        public async Task<IActionResult> CreatePlanAttraction([FromBody] PlanAttractionDTO planAttractionDTO)
        {
            var response = await _planAttractionService.CreatPlanAttraction(planAttractionDTO);
            return Ok(response);
        }


        [HttpPut("update")]
        [SwaggerOperation(Summary = "更新一个计划景点", Description = "更新一个计划景点")]
        [SwaggerResponse(200, "更新成功", typeof(Response<PlanAttraction>))]
        [SwaggerResponse(400, "更新失败")]
        public async Task<IActionResult> UpdatePlanAttraction(long planAttractionId, [FromBody] PlanAttractionDTO planAttractionDTO)
        {
            var response = await _planAttractionService.UpdatePlanAttraction(planAttractionId, planAttractionDTO);
            return Ok(response);
        }


        [HttpDelete("delete/{planAttractionId}")]
        [SwaggerOperation(Summary = "删除一个计划景点", Description = "删除一个计划景点")]
        [SwaggerResponse(200, "删除成功", typeof(Response<string>))]
        [SwaggerResponse(400, "删除失败")]
        public async Task<IActionResult> DeletePlanAttraction(long planAttractionId)
        {
            var response = await _planAttractionService.DeletePlanAttraction(planAttractionId);
            return Ok(response);
        }


        [HttpGet("detail/{planAttractionId}")]
        [SwaggerOperation(Summary = "通过ID获取计划景点", Description = "通过ID获取计划景点")]
        [SwaggerResponse(200, "获取成功", typeof(Response<PlanAttraction>))]
        [SwaggerResponse(400, "获取失败")]
        public async Task<IActionResult> GetPlanAttractionById(long planAttractionId)
        {
            var response = await _planAttractionService.GetPlanAttractionById(planAttractionId);
            return Ok(response);
        }


        [HttpGet("list/{planId}")]
        [SwaggerOperation(Summary = "通过计划ID获取计划景点", Description = "通过计划ID获取计划景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<PlanAttraction>))]
        [SwaggerResponse(400, "获取失败")]
        public async Task<IActionResult> GetPlanAttractionsByPlanId(long planId, int pageNumber, int pageSize)
        {
            var response = await _planAttractionService.GetPlanAttractionsByPlanId(planId, pageNumber, pageSize);
            return Ok(response);
        }


        [HttpDelete("delete/plan/{planId}")]
        [SwaggerOperation(Summary = "通过计划ID删除计划景点", Description = "通过计划ID删除计划景点")]
        [SwaggerResponse(200, "删除成功", typeof(Response<string>))]
        [SwaggerResponse(400, "删除失败")]
        public async Task<IActionResult> DeletePlanAttractionsByPlanId(long planId)
        {
            var response = await _planAttractionService.DeletePlanAttractionsByPlanId(planId);
            return Ok(response);
        }


        [HttpPut("change-visit-order/{planAttractionId}")]
        [SwaggerOperation(Summary = "改变访问顺序", Description = "改变访问顺序，返回新的景点-顺序对列表")]
        [SwaggerResponse(200, "修改成功", typeof(PageResponse<ChangeVisitOrderVO>))]
        [SwaggerResponse(400, "修改失败")]
        public async Task<IActionResult> ChangeVisitOrder(long planAttractionId, int newVisitOrder)
        {
            var response = await _planAttractionService.ChangeVisitOrder(planAttractionId, newVisitOrder);
            return Ok(response);
        }


    }
}
